<template>
  <section class="home">
    <header class="header">
      <h1>上海铁路公安局大数据综合应用平台</h1>
    </header>
    <!-- 登录信息模块 -->
    <div class="login-user">
      <span class="user-name">欢迎您 , {{ user }}</span>
      <i class="iconfont icon-exit" title="退出" @click="logOut"></i>
    </div>
    <nav class="nav">
      <ul>
        <li><a :href="tToken" target="_blank">智能云搜</a></li>
        <li><a href="http://10.3.208.111:9085/tlgaj_st/precaution/pre_list" target="_blank">实时预警</a></li>
        <li><a href="http://10.3.208.111:9085/tlgaj_st/direction/revce_list" target="_blank">情指流转</a></li>
        <li><a href="javascript:void(0)">分析研判</a></li>
        <li><a href="http://10.3.208.4/UploadFiles/map/20170505.jpg" target="_blank">铁路路线图</a></li>
      </ul>
    </nav>
    <div class="home-main clearfix">
      <div class="left">
        <div class="maparea sectionbg">
          <home-map chartId="homemap" :option="options"></home-map>
        </div>
      </div>
      <div class="right">
        <notice :noticeItem="noticeList" :total="totals" v-on:page="changePage"></notice>
        <div class="message sectionbg">
          <h3>
            <p>消息提醒</p>
            <!-- <div class="avater-wrapper">
              <div class="cirle1"></div>
              <div class="cirle2"></div>
              <div class="cirle3"></div>
            </div> -->
          </h3>
          <ul>
            <li>网上逃犯：<i>{{ messageData.v1 }}</i>人</li>
            <li>布控对象：<i>{{ messageData.v2 }}</i>人</li>
            <li>重点人员：<i>{{ messageData.v3 }}</i>人</li>
          </ul>
        </div>
      </div>
    </div>
  </section>
</template>

<script>
import { formatDateTime } from '../util/tool'
import { getTableApi, getNoticeList, getUserInfo, loginOut } from '../api/api'
import homeMap from '../components/home/homemap'
import notice from '../components/home/notice'

export default {
  components: {
    homeMap,
    notice
  },
  data() {
    return {
      tToken: 'http://10.3.211.23/',
      user: '',
      options: [],
      totals: 5,
      page: 1,
      noticeList: [
        {
          title: '推进党务公开 让权力在阳光下运行——中央.',
          publish_time: '2018-06-06'
        },
        {
          title: '中共中央印发《中国共产党党务公开条例（试...',
          publish_time: '2018-06-06'
        },
        {
          title: '【监察体制改革】询问：认定案件事实的必备...',
          publish_time: '2018-06-06'
        },
        {
          title: '上海市深化监察体制改革试点工作小组第二次...',
          publish_time: '2018-06-06'
        },
        {
          title: '赵乐际在福建调研时强调深入贯彻党的十九大...',
          publish_time: '2018-06-06'
        }
      ],
      messageData: {}
    }
  },
  created() {
    this.getToken();
  },
  mounted() {
    this.getUser();
    this.getMessage('bkyjzs',this.messageData);
    this.getNotice();
  },
  methods: {
    // 修改智能云搜token
    getToken(){
      this.tToken = "http://10.3.211.23:80/?token=" + this.getCookie('token');
    },
    getCookie(name){
      let arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
      if(arr=document.cookie.match(reg))
        return unescape(arr[2]);
      else
        return null;
    },
    // 消息提醒
    getMessage(tableName,data){
      getTableApi(tableName).then((res) => {
        let resdata = res.data.data.count;
        for(let k in resdata){
          if(resdata[k].k1 == '在逃人员'){
            data['v1'] = resdata[k].v1;
          }
          if(resdata[k].k1 == '重点人员'){
            data['v3'] = resdata[k].v1;
          }
          if(resdata[k].k1 == '布控对象'){
            data['v2'] = resdata[k].v1;
          }
        }
        this.$set(this.messageData,0,data);
      });
    },
    // 通知通报
    getNotice(){
      getNoticeList({ page: this.page, rows: 5 }).then((res) => {
        let rdata = res.data.data;
        this.totals = rdata.total;
        this.noticeList = [];
        for(let i in rdata.rows){
          this.noticeList.push(rdata.rows[i]);
        }
        for(let j in this.noticeList){
          this.noticeList[j].publish_time = formatDateTime(this.noticeList[j].publish_time);
        }
      });
    },
    changePage(val) {
      // childValue就是子组件传过来的值
      this.page = val;
      this.getNotice();
    },
    // 获取用户信息
    getUser(){
      getUserInfo({ token: this.getCookie('token') }).then((res) => {
        this.user = res.data.result.userName;
      });
    },
    // 删除cookie
    delCookie(name){
      var exp = new Date();
      exp.setTime(exp.getTime() - 1);
      var cval = this.getCookie(name);
      if(cval!=null)
      document.cookie= name + "="+cval+";expires="+exp.toGMTString();
    },
    // 退出当前登录 清楚token
    logOut(){
      // loginOut({ token:this.getCookie('token') });
      const baseUrl = process.env.NODE_ENV === 'development' ? 'https://192.168.0.181:8101/login':'http://10.3.208.111:9085/tlgaj_st/portal/token/logout';
      this.delCookie('token');
      window.location.href = baseUrl;
    }
  }
}
</script>

<style lang="scss">
@import '../assets/font/iconfont.css';
@import '../assets/sass/common.scss';
@import '../assets/sass/homePage.scss'
</style>
